/*
 * (c) Copyright 2009 Hewlett-Packard Development Company, LP
 * All rights reserved.
 * [See end of file]
 */

package com.hp.hpl.jena.clusteredtdb.pgraph;

import lib.ColumnMap;

import com.hp.hpl.jena.clusteredtdb.ClusteredTDBConfig;
import com.hp.hpl.jena.clusteredtdb.comms.ClusterRepresentation;
import com.hp.hpl.jena.tdb.base.file.Location;
import com.hp.hpl.jena.tdb.index.IndexBuilder;
import com.hp.hpl.jena.tdb.index.TupleIndex;
import com.hp.hpl.jena.tdb.nodetable.NodeTable;
import com.hp.hpl.jena.tdb.store.FactoryGraphTDB;
import com.hp.hpl.jena.tdb.store.GraphTDB;
import com.hp.hpl.jena.tdb.store.TripleTable;

public class NetworkedGraphTDBFactory {

	public static GraphTDB create(Location location, ClusterRepresentation cr, ClusteredTDBConfig ctdb) {
		NetworkedRangeIndex idxSPO = new NetworkedRangeIndex(cr, Names2.indexSPO);
		NetworkedRangeIndex idxPOS = new NetworkedRangeIndex(cr, Names2.indexPOS);
		NetworkedRangeIndex idxOSP = new NetworkedRangeIndex(cr, Names2.indexOSP);
		
		BulkTupleIndex triplesSPO = new BulkTupleIndex(3, new ColumnMap("SPO", Names2.indexSPO), FactoryGraphTDB.indexRecordTripleFactory, idxSPO) ;
		BulkTupleIndex triplesPOS = new BulkTupleIndex(3, new ColumnMap("SPO", Names2.indexPOS), FactoryGraphTDB.indexRecordTripleFactory, idxPOS) ;
		BulkTupleIndex triplesOSP = new BulkTupleIndex(3, new ColumnMap("SPO", Names2.indexOSP), FactoryGraphTDB.indexRecordTripleFactory, idxOSP) ;
		
		// Creates the object file as a file-backed one. 
        NodeTable nodeTable = new NetworkedNodeTable(IndexBuilder.get(), location, cr, ctdb.getNodeMask()) ;

        TupleIndex[] tupleIndex = {triplesSPO, triplesPOS, triplesOSP} ;
        TripleTable tripleTable = new TripleTable(tupleIndex, FactoryGraphTDB.indexRecordTripleFactory, nodeTable, null) ;
        return new NetworkedGraphTDB(tripleTable, nodeTable) ;
	}
	
}

/*
 * (c) Copyright 2009 Hewlett-Packard Development Company, LP
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
